package server.model.solver.maze;

import server.model.solver.maze.algorithms.*;

public class Maze {
	public static final int WALL_INDICATOR = -1;
	public static final int EMPTY_INDICATOR = 0;
	public static final int START_INDICATOR = 1;
	public static final int GOAL_INDICATOR = 3;
	
	private final int[][] maze;
	private final int xLength;
	private final int yLength;

	public Maze(int[][] matrix) {
		this.maze = matrix;
		this.xLength = this.maze[0].length;
		this.yLength = this.maze.length;
	}

	public State getStartState() {
		MazeState mazeState = new MazeState();

		// Find the location of the mouse in the maze
		for (int x = 0; x < xLength; x++)
			for (int y = 0; y < yLength; y++)
				if (get(x, y) == START_INDICATOR) {
					mazeState.setX(x);
					mazeState.setY(y);
					break;
				}

		return mazeState;
	}

	public State getGoalState() {
		MazeState mazeState = new MazeState();

		// Find the location of the cheese in the maze
		for (int x = 0; x < xLength; x++)
			for (int y = 0; y < yLength; y++)
				if (get(x, y) == GOAL_INDICATOR) {
					mazeState.setX(x);
					mazeState.setY(y);
					break;
				}

		return mazeState;
	}

	public int get(int x, int y) {
		// Check for illegal input
		if (x < 0 || x >= xLength || y < 0 || y >= yLength) {
			return -1;
		}
		else {
			return maze[y][x];
		}
	}
}
